package com.gongj.main;

import com.gongj.entity.Person;
import com.gongj.entity.User;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.ChildBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class ChildBeanDefinitionTest {
	public static void main(String[] args) {
		//容器
		DefaultListableBeanFactory context = new DefaultListableBeanFactory();
		//普通属性的集合  在其父类 AbstractBeanDefinition 已经提到过了
		MutablePropertyValues mpvs = new MutablePropertyValues();
		mpvs.add("id",4L);
		mpvs.add("name","gongj");
		//BeanDefinition
		RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(User.class,null,mpvs);
		//注册到Spring容器中
		context.registerBeanDefinition("user",rootBeanDefinition);

		// ChildBeanDefinition 开始
		MutablePropertyValues childValues = new MutablePropertyValues();
		childValues.add("address","上海市");
		//通过构造方法传入父 BeanDetintion 的名称
		ChildBeanDefinition childBeanDefinition  = new ChildBeanDefinition("user", Person.class,null,childValues);
		//注册
		context.registerBeanDefinition("perTestAwareson", childBeanDefinition);

		User user = context.getBean(User.class);
		Person person = context.getBean(Person.class);
		System.out.println("user = " + user);
		System.out.println("person = " + person);
	}
}
